from fastapi import APIRouter, Depends
from sqlalchemy.ext.asyncio import AsyncSession

from project.dependents import get_current_user, get_db
from project.models import UserInDB
from project.user.schemas import User, UserCreate
from project.user.service import create_user

user_api = APIRouter()


@user_api.get('/user', response_model=User)
async def get_user(current_user: User = Depends(get_current_user)):
    """
    获取当前登录用户数据
    :param current_user:
    :return:
    """
    return current_user


@user_api.post("/user/create", response_model=User)
async def user_create(user_info: UserCreate, db: AsyncSession = Depends(get_db)):
    """
    创建新用户
    :param user_info:
    :param db:
    :return:
    """
    user: UserInDB = await create_user(db, user_info)
    return user
